package com.cmsz.uregs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cmsz.uregs.dao.UserRepository;
import com.cmsz.uregs.entity.User;
import com.cmsz.uregs.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserRepository UserRepository;

	@Override
	@Transactional
	public User addUser(User user) {
		return UserRepository.saveAndFlush(user);
	}

	public List<User> findAllUsers() {
		return UserRepository.findAll();
	}

	@Override
	@Transactional
	public void deleteUser(int id) {
		UserRepository.delete(id);
	}

	public User findUser(int id) {
		return UserRepository.findOne(id);
	}

	@Override
	public User findUserByName(String username) {
		return UserRepository.findByUsername(username);
	}

	@Override
	@Transactional
	public void updateUser(User user) {
		UserRepository.saveAndFlush(user);
	}
}
